﻿<cfscript>
/** 
* ORM StudentChange
* 
* @hint "Hibernate persistenter t_stuchange. 学生学籍异动记录" 
* 
*/ 

component 
	displayname="public.service.orm.senate.StudentChange" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="StudentChange" 
	table="t_stuchange"
	{
	
	property type="string" name="ChangeID" column="stuchg_id" fieldtype="id" generator="assigned" hint="学籍异动编号";

	property type="string" name="ChangeDate" column="change_date" hint="异动日期";
	property type="string" name="ApproveDate" column="approve_date" hint="审批日期";
	property type="string" name="ApproveDocument" column="approve_docid" hint="审批文号";
	property type="string" name="Source" column="stu_source" hint="异动来源";
	property type="string" name="Target" column="stu_newlocation" hint="异动去向";
	property type="string" name="Description" column="op_description" hint="异动说明";

	property type="string" name="Institute" column="institute_name" hint="原学院";
	property type="string" name="Subject" column="subject_name" hint="原专业";
	property type="string" name="Grade" column="grade" hint="原年级";
	property type="string" name="FormClass" column="class_name" hint="原班级";

	property name="Student" fieldtype="many-to-one" fkcolumn="stu_id" cfc="Student"  hint="学生";
	property name="Type" fieldtype="many-to-one" fkcolumn="sct_code" cfc="StudentChangeType"  hint="异动类别";
	property name="Term" fieldtype="many-to-one" fkcolumn="term_id" cfc="Term"  hint="学期";
	property name="Admin" fieldtype="many-to-one" fkcolumn="admin_user_id" cfc="Teacher"  hint="管理岗位教师";
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Output false
	* 
	*/
	public string function getNextID() {
		
		var nextID = year(now()) & numberFormat(1, "0_____");
		
		var checkArray = ORMExecuteQuery("select ChangeID from StudentChange 
											where ChangeID like :condition 
											order by ChangeID desc", {condition = year(now()) & "______"}, { maxResults=1 });
		
		/* 
			主键生成规则 
			
			异动代码为10位, 4位年份 余下6位为流水号
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = year(now()) & numberFormat((right(checkArray[1], 6) + 1), "0_____");
			
		}

		return nextID;
		
	}
	
}

</cfscript>